package com.csweimei.rentmanagementtreasure.tenant.ui.act.house;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import android.content.Intent;
import android.os.Bundle;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityAddZyHouseBinding;
import com.csweimei.rentmanagementtreasure.http.entity.CustomerBean;
import com.csweimei.rentmanagementtreasure.tenant.viewModel.AddZyHouseVM;

import me.goldze.mvvmhabit.base.BaseActivity;

/**
 * 添加整租合约
 */
public class AddZzZyHouseActivity extends BaseActivity<ActivityAddZyHouseBinding, AddZyHouseVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_add_zy_house;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public AddZyHouseVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(AddZyHouseVM.class);
    }

    String houseId = "0";
    @Override
    public void initParam() {
        super.initParam();
        houseId = getIntent().getStringExtra("id");
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        viewModel.housingID.set(houseId+"");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 10087){
            CustomerBean.DataDTO dataDTO = (CustomerBean.DataDTO) data.getSerializableExtra("data");
            viewModel.name.set(dataDTO.getName());
            viewModel.contact.set(dataDTO.getPhone());
            viewModel.IDCard.set(dataDTO.getIDCard());
            viewModel.customID.set(dataDTO.getId()+"");
        }
    }
}